<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/3/16 0016
 * Time: 22:30
 */

namespace app\admin\controller;


use app\admin\model\Users;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class User extends BaseController
{
   public function user(){
       $user=Users::getUsersList();

       View::assign("user",$user);
       return View::fetch();
   }
    public function userAdd(){
       if (Request::isPost()){
           $param=Request::param();
           $data=[
             'uname'=>$param['uname'],
               'upwd'=>md5($param['upwd']),
               'tel'=>$param['tel'],
               'add_time'=>date("Y-m-d H:i:s",time())
           ];
           list($res,$msg)=Users::addUsersInfo($data);
           if ($res){
               //成功
               $this->success($msg,url('user'),[],3);
           }else{
               //失败
               $this->error($msg,url('user'),[],3);
           }

       }else{
           return View::fetch();
       }

    }
    public function userEdit(){

     if (Request::isPost()){
         $param=Request::param();
        $data=[
            'userid'=>$param['id'],
             'add_time'=>date('Y-m-d H:i:s',time())
             //'upwd'=>$param['reset'],
        ];
       list($res,$msg)=Users::editUserList($data);
       if ($res){
           $this->success($msg,url('user'),[],3);
       }else{
           $this->error($msg,url('user'),[],3);
       }
     }else{
         $param=Request::param();
         //$id=Request::get('id');
         //展示原来数据
         $users=Users::find($param['id'])->toArray();
         echo "<pre>";
         print_r($users);
         echo "</pre>";

         View::assign("users",$users);
     }
        return View::fetch();
    }
    public function auth(){
        return View::fetch();
    }
    public function authAdd(){
        return View::fetch();
    }
}